/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.menu;

import java.util.List;

import org.rails.extjs.Container;
import org.rails.extjs.Option;
import org.rails.extjs.layout.Layout;
import org.rails.extjs.layout.MenuLayout;

public class Menu extends Container {

	public Menu() {
		super();
	}

	public Menu(Option configOptions) {
		super(configOptions);
	}

	public Menu(String id) {
		super(id);
	}
	
	public void setAllowOtherMenus(Boolean allowOtherMenus){
		addOption("allowOtherMenus", allowOtherMenus);
	}
	
	public Boolean isAllowOtherMenus(){
		return getBoolean("allowOtherMenus",false);
	}
	
	public void setDefaultAlign(String defaultAlign){
		addOption("defaultAlign", defaultAlign);
	}

	public String getDefaultAlign(){
		return getString("defaultAlign","tl-bl?");
	}
	
	public void setDefaultOffsets(List<Number> defaultOffsets){
		addOption("defaultOffsets", defaultOffsets);
	}
	
	@SuppressWarnings("unchecked")
	public List<Number> getDefaultOffsets(){
		return (List<Number>)getOption("defaultOffsets");
	}
	
	public void setEnableScrolling(Boolean enableScrolling){
		addOption("enableScrolling", enableScrolling);
	}
	
	public Boolean isEnableScrolling(){
		return getBoolean("enableScrolling",true);
	}
	
	public void setFloating(Boolean floating){
		addOption("floating", floating);
	}
	
	public Boolean isFloating(){
		return getBoolean("floating", false);
	}
	
	public void setIgnoreParentClicks(Boolean ignoreParentClicks){
		addOption("ignoreParentClicks", ignoreParentClicks);
	}
	
	public Boolean isIgnoreParentClicks(){
		return getBoolean("ignoreParentClicks",false);
	}	

	public Layout getLayout(){
		return getOption("layout") == null ? new MenuLayout() : (MenuLayout)getOption("layout");
	}
	
	public void setMaxHeight(Integer maxHeight){
		addOption("maxHeight", maxHeight);
	}
	
	public Integer getMaxHeight(){
		return getInteger("maxHeight",0);
	}
	
	public void setMinWidth(Integer minWidth){
		addOption("minWidth", minWidth);
	}
	
	public Integer getMinWidth(){
		return getInteger("minWidth",120);
	}
	
	public void setScrollIncrement(Integer scrollIncrement){
		addOption("scrollIncrement", scrollIncrement);
	}
	
	public Integer getScrollIncrement(){
		return getInteger("scrollIncrement",24);
	}
	
	public void setShadow(Boolean shadow){
		addOption("shadow", shadow);
	}
	
	public Boolean isShadow(){
		return getBoolean("shadow",true);
	}
	
	public void setShowSeparator(Boolean showSeparator){
		addOption("showSeparator", showSeparator);
	}
	
	public Boolean isShowSeparator(){
		return getBoolean("showSeparator",true);
	}
	
	public void setSubMenuAlign(String subMenuAlign){
		addOption("subMenuAlign", subMenuAlign);
	}
	
	public String getSubMenuAlign(){
		return getString("subMenuAlign", "tl-tr?");
	}
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.menu.Menu(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
